const gulp = require('gulp')
const cssmin = require('gulp-cssmin')
const uglify = require('gulp-uglify')
const babel = require('gulp-babel')
const htmlmin = require('gulp-htmlmin')
// css
const cssHandler = () =>{
   return gulp
    .src('./src/css/*.css')
    .pipe(cssmin())
    .pipe(gulp.dest('./dist/css/'))
}
// js
const jsHandler = ()=>{
    return gulp
    .src('./src/js/*.js')
    .pipe(babel({presets: ['@babel/preset-env'] }))
    .pipe(uglify())
    .pipe(gulp.dest('./dist/js/'))
}
// html
const htmlHandler = ()=>{
    return gulp
    .src('./src/views/*.html')
    .pipe(htmlmin({
        collapseWhitespace:true,
        collapseBooleanAttributes:true,
        removeAttributeQuotes:true,
        removeComments:true,
        removeEmptyAttributes:true,
        removeScriptTypeAttributes:true,
        removeStyleLinkTypeAttributes:true,
        minifyCSS:true,
        minifyJS:true,
    }))
    .pipe(gulp.dest('./dist/views/'))
}
// 结束
module.exports = {
    cssHandler: cssHandler,
    jsHandler :jsHandler,
    htmlHandler:htmlHandler,
}